

var vm = new Vue({
    el:"#app",
    data:{
        role:'',
        dept:'',
        addFlag:'',
        position:''
    },
    methods:{
        getDeptList:function () {
            axios.post("/dept/queryDept").then(
                function(result){
                    vm.dept=result.data;
                    console.log(vm.dept);
                },function (err) {
                    console.log(err);
                }
            )
        },
        getRoleList:function () {
            axios.post("/role/queryRolesByCondition").then(
                function(result){
                    vm.role=result.data;
                    console.log(vm.role);
                },function (err) {
                    console.log(err);
                }
            )
        },
        getPositionList:function () {
            axios.post("/staff/queryPositionList").then(
                function(result){
                    vm.position=result.data;
                    console.log(vm.position);
                },function (err) {
                    console.log(err);
                }
            )
        },
        addStaff:function (){
            let flag = true;
            let name = $("input[name='name']").val();
            if (name === ""){
                flag = false;
            }
            let password = $("input[name='password']").val();
            let tel = $("input[name='tel']").val();
            if (tel === ""){
                flag = false;
            }
            let email = $("input[name='email']").val();
            if (email === ""){
                flag = false;
            }
            let sex = $("input[name='sex']").eq(0).attr("checked") === true?"1":"0";
            let age = $("input[name='age']").val();
            if (age === ""){
                flag = false;
            }
            let roleName = $(".roleName").val();
            if (roleName === "请选择"){
                flag = false;
            }
            let deptName = $(".deptName").val();
            if (deptName === "请选择"){
                flag = false;
            }
            let position = $(".position").val();
            if (position === "请选择"){
                flag = false;
            }
            if (flag){
                axios.post("/staff/addStaff",{name:name,password:password,tel:tel,email:email,sex:sex,age:age,roleName:roleName,deptName:deptName,position:position}).then(
                    function(result){
                        vm.addFlag = result.data;
                        console.log(vm.addFlag);
                        if (vm.addFlag){
                            alert("添加员工成功");
                            location.href = "../../../../templates/sysManage/staffManage/staffList.html";
                        }else {
                            alert("添加员工失败");
                        }
                    },function (err) {
                        console.log(err);
                    }
                )
            }else {
                alert("您的信息还未填写完全");
            }
        }
    },
    //页面加载完自动执行
    mounted(){
        this.getDeptList();
        this.getRoleList();
        this.getPositionList();
    }
})
